package com.zby.big_event_zby.learnTest;

/**
 * @version 1.0
 * @auther ZBY
 */
public class SellTicket {
    public static void main(String[] args) {
        SellTicket01 sellTicket01 = new SellTicket01();
        Thread thread0 = new Thread(sellTicket01);
        Thread thread1 = new Thread(sellTicket01);
        Thread thread2 = new Thread(sellTicket01);
        thread0.setName("窗口0");
        thread1.setName("窗口1");
        thread2.setName("窗口2");

        thread0.start();
        thread1.start();
        thread2.start();
    }
}
class SellTicket01 implements Runnable {

    private static int ticketNum = 100;
    @Override
    public void run(){
        while (true){
            if (ticketNum<=0){
                System.out.println("票已卖完");
                break;
            }
            try {
                Thread.sleep(5);
            }catch (Exception e){
                e.printStackTrace();
            }
            if (ticketNum != 0){
                System.out.println(Thread.currentThread().getName()+"卖票，票号为："+(--ticketNum));
            }

        }
    }
}